package main

func main() {
	a := 1
	b := [][]int{{1, 2, 8, 9}, {2, 4, 9, 12}, {4, 7, 10, 13}, {6, 8, 11, 15}}
	print(Find(a, b))
}

func Find(target int, array [][]int) bool {
	for _, num := range array {
		if len(num) > 1 && num[0] <= target {
			if BinarySearch(num, target) != -1 {
				return true
			}
		} else {
			break
		}
	}
	return false
}

func BinarySearch(n []int, target int) int {
	length := len(n)
	low := 0
	high := length - 1
	for low <= high {
		mid := (low + high) / 2
		if n[mid] > target {
			high = mid - 1
		} else if n[mid] < target {
			low = mid + 1
		} else {
			return mid
		}
	}
	return -1
}


func Find1( target int ,  array [][]int ) bool {
	// write code here
	if array == nil{
		return false
	}
	len1 := len(array)
	len2 := len(array[0])
	i,j:=0,len2-1

	for i<=len1-1 && j>=0{
		if array[i][j] > target{
			j--
		}else if array[i][j] < target{
			i++
		}else{
			return true
		}
	}
	return false
}